package tool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class GetVertexOfEdge {
	public static int[][] getEdges() {
		File fileEdge = new File(Settings.vertexofEdge);
		int rows = getFileRows(fileEdge);
		int numOfVertex = GetVertex.getVertex().length;
		int[][] edges = new int[numOfVertex][numOfVertex];
		int startPoint = 0;
		int endPoint = 0;
		try {
			FileReader fr = new FileReader(fileEdge);
			BufferedReader br = new BufferedReader(fr);
			for (int i = 0; i < rows; i++) {
				try {
					String line = br.readLine();
					String[] arr = line.split(",");
					startPoint = Integer.parseInt(arr[0]);
					endPoint = Integer.parseInt(arr[1]);
					edges[endPoint][startPoint] = 1;
					edges[startPoint][endPoint] = 1;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return edges;
	}

	public static int getFileRows(File file) {
		int rows = 0;
		try {
			FileInputStream fis = new FileInputStream(file);
			Scanner sc = new Scanner(fis);
			while (sc.hasNextLine()) {
				rows++;
				sc.nextLine();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rows;
	}

}
